<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: blog.php 502 2014-01-31 15:50:06Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 502 $
* 	zuletzt geändert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-31 15:50:06 +0000 (Fri, 31 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$blog_smarty = new Smarty();

if (!CacheCheck()) {
	$cache = false;
	$blog_smarty->caching = false;

} else {
	$cache = true;
	$blog_smarty->caching = true;
	$blog_smarty->cache_lifetime = CACHE_LIFETIME;
	$blog_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = 'box_blog_'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_id'].'_'.$_GET['blog_cat'].'_'.$_GET['blog_item'];
}

if(!$blog_smarty->isCached(CURRENT_TEMPLATE.'/boxes/box_blog.html', $cache_id) || !$cache){	
	$categories_array = array();
	$cats = 0; $item = 0;
	
	$categories = $db->db_query("SELECT 
									categories_id, titel, date
								FROM 
									".TABLE_BLOG_CATEGORIES."
								WHERE 
									status = '2'
								AND 
									language_id = '".$_SESSION['languages_id']."'
								ORDER BY 
									position, id ASC");
	
	while(!$categories->EOF){
		
		if($_GET['blog_cat'] == $categories->fields['categories_id'])
			$blog_cat_active = ' blog_titel_active';
		else
			$blog_cat_active = '';
		
	    $categories_array[$cats] = array('CATEGORIE_ID'		=> $categories->fields['categories_id'],
									      'CATEGORIE_TITLE'  => $categories->fields['titel'],
									      'CATERORIE_ACTIVE' => $blog_cat_active,
									      'CATEGORIE_LINK'   => href_link(FILENAME_BLOG,'blog_cat='.$categories->fields['categories_id']));
	    // Einzelne Einträge
		if(isset($_GET['blog_cat']) && !empty($_GET['blog_cat']) && ($_GET['blog_cat'] == $categories->fields['categories_id'])) {
			$items = $db->db_query("SELECT
											item_id, title, date
										FROM
											".TABLE_BLOG_ITEMS."
										WHERE
											status = '2'
										AND
											categories_id = '".$categories->fields['categories_id']."'
										AND
											language_id = '".(int)$_SESSION['languages_id']."'
										ORDER BY
											position ASC, date DESC");
	
			$categories_array[$cats]['ITEMS'] = array();
			if($items->_numOfRows) {
				while(!$items->EOF){
		    		if($_GET['blog_item'] == $items->fields['item_id'])
		    			$blog_id_active = ' blog_active';
		    		else
		    			$blog_id_active = '';
	
					$categories_array[$cats]['ITEMS'][$item] = array('ITEM_ID' => $items->fields['item_id'],
																	'ITEM_TITLE' => $items->fields['title'],
																	'ITEM_ACTIVE' => $blog_id_active,
																	'ITEM_LINK' => href_link(FILENAME_BLOG,'blog_cat='.$categories->fields['categories_id'].'&blog_item='.$items->fields['item_id'])
					);
					$item++;
					$items->MoveNext();
				}
			}
		}
	    $cats++;
	    $categories->MoveNext();
	}
	
	$blog_smarty->assign('tpl_path','templates/'.CURRENT_TEMPLATE.'/');
	$blog_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	$blog_smarty->assign('categories', $categories_array);
	$blog_smarty->assign('language', $_SESSION['language']);
	$blog_smarty->assign('LINK', href_link(FILENAME_BLOG, 'blog_cat'));
}

if(!$cache)
	$box_content = $blog_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_blog.html');
else
	$box_content = $blog_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_blog.html', $cache_id);